package net.message;

import net.message.processor.IMessageProcessor;
import net.Client;
import net.Util;

public class GetImageResponseMessage implements Message{

    public final int[] image;
    public final int imageID;

    public GetImageResponseMessage(int[] image, int imageID) {
        this.image = image;
        this.imageID = imageID;
    }

    public GetImageResponseMessage(byte[] source) {
        assert(source.length % 4 == 0);
        image = Util.byteArrayToIntArray(source, 0, source.length / 4 - 1);
        imageID = Util.byteArrayToInt(source, source.length - 4);
    }

    @Override
    public void accept(IMessageProcessor processor, Client client) {
        processor.process(this, client);
    }

    @Override
    public byte[] toByteArray() {
        byte[] res = new byte[(image.length + 1) * 4];
        Util.intArrayToByteArray(image, res, 0);
        Util.intToByteArray(imageID, res, image.length * 4);
        return res;
    }

    @Override
    public MessageType getType(){
        return MessageType.GET_IMAGE_RESPONSE;
    }


}